﻿using System.Runtime.Serialization;
using EzDesk.Core.Model;

namespace EzDesk.Core.Model
{
    public static class UserProfileExt
    {
        public static UserProfile ToUserProfile(this SimpleUser user)
        {
            if (user == null) return null;
            return new UserProfile
                       {
                           Id = user.Id,
                           Name = user.Name,
                           UserCode = user.UserName,
                           DeptId = user.Dept.Id,
                       };
        }

        public static SimpleUser ToSimpleUser(this UserProfile user)
        {
            if (user == null) return null;
            var simpleUser = new SimpleUser
                       {
                           Id = user.Id,
                           Name = user.Name,
                           UserName = user.UserCode,
                           Dept = user.Dept,
                           Position = user.Position,
                       };
            if (simpleUser.Dept == null)
            {
                simpleUser.Dept = Dept.NullObject;
            }
            if (simpleUser.Position == null)
            {
                simpleUser.Position = Position.NullObject;
            }
            return simpleUser;
        }
    }

    public partial class UserProfile
    {
        [DataMember]
        public string HeadUrl { get; set; }
    }
}